home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 11: TSX-11 / Linux Cubed Series 11 - TSX-11 Vol 1.iso / usr.bin / doshell.c < prev    next >
C/C++ Source or Header  |  1996-11-30  |  600b  |  35 lines

  1.  
  2. #include <stdio.h>
  3. #include <sys/file.h>
  4. #include <errno.h>
  5.  
  6. extern char *sys_errlist[];
  7.  
  8. main(int argc, char *argv[])
  9. {
  10.  
  11.     if (argc != 3) {
  12.     fprintf(stderr, "usage: doshell <ttyname> <shellname> &\n");
  13.     exit(1);
  14.     }
  15.  
  16.     /* close down fd's */
  17.     close(0);
  18.     close(1);
  19.     close(2);
  20.  
  21.     /* detach from parent process's group */
  22.     setsid();
  23.  
  24.     /* open new tty */
  25.     if (open(argv[1], O_RDWR, 0) == -1)
  26.     exit(2);
  27.     dup(0);
  28.     dup(0);
  29.     execlp(argv[2], "-", 0);
  30.     /* should appear on new tty...: */
  31.     fprintf(stderr, "can't exec shell: %s\n", sys_errlist[errno]);
  32.     exit(3);
  33. }
  34.  
  35.